home *** CD-ROM | disk | FTP | other *** search
- /*
-
- bfile.h
- Btrieve class for Borland C++
- 09/06/91
-
- Douglas J. Reilly
- Access Microsystems Inc.
- 404 Midstreams Road
- Brick, New Jersey 08724
- (908) 892-2683
- CompuServe 74040,607
-
- Comments? Questions? Suggestions?
- Have a paying C/C++ programming job you need done?
- Give me a call.
-
- Released into the public domain. Do with it as you see fit, but
- if you do anything really neat with it, let me know...
-
- 10/15/91 DR Make len default to 0 in constructor, and then set it from
- open return.
- Set newmode in open() call to -99 by default, ensures
- that we realize that no mode was sent.
- 11/11/91 DR Multiple fixes and changes to better handle variable length
- records.
- Add clone_file() to public interface.
- */
-
- #ifndef BFILE_H
- #define BFILE_H
- #include "btrieve.h"
- extern "C" {
- int BTRV(int ,char *,char *,int *,char *,int );
- }
-
- class bfile {
- char pos_blk[128]; // position block
- char fname[64]; // physical file name
- char logical_name[10]; // logical file name (not used yet)
- int mode; // open mode
- int file_flag; // flag from STAT call.
- int fixed_len; // The non-variable length.
- int rec_len; // record length, i.e. higher than above for
- // variable lenght records.
- // This is == to above UNLESS you pass
- // a length to constructor. For variable
- // length records, you MUST pass a length
- // that is the upper limit you expect.
- int last_rec_len; // most recent returned len
- int key_num; // current key number
- int num_keys; // number of keys in file
- int status; // error status
- int opened; // opened flag, not really essential because data
- // seemed like it was as natural a flag
- // as possible, since we don't want to write
- // data to null.
- char *data; // The data, of course...
- char owner[60]; // owner of the file, used for secured files.
- public:
- // file name, lenght, owner, and open mode
- // Note that constructor opens file, destructor closes.
- bfile(char *name,int len=0,char *towner=0,int newmode=0);
- ~bfile();
- // Close file, free up data pointer above.
- int close();
- // Open, really SB reopen I guess since only useful after close...
- int open(int newmode=-99);
- // Gets a record. Uses key 0 unless you set key number (below).
- int get_rec(char *keystr,int op=B_GET_EQ);
- // Self explanatory...
- void set_key_num(int key=0)
- {
- // sanity check...
- if ( key<num_keys )
- {
- key_num=key;
- }
- }
- int get_key_num() { return key_num; }
- int get_key_len(int key_num=-1);
- // Get the number of keys allowed.
- int get_num_keys() { return num_keys; }
- // take newdata and copy it into the data element.
- int set_data(char *newdata)
- {
- if ( data!=NULL )
- {
- memcpy(data,newdata,rec_len);
- return(1);
- }
- return(0);
- }
- // return pointer to data.
- char *get_data(int *last_len=0)
- {
- if ( last_len!=0 )
- {
- *last_len=last_rec_len;
- }
- return data;
- }
- // return pointer to COPY data.
- char *dup_data()
- {
- char *datacopy=0;
- if ( opened && data!=0 )
- {
- datacopy=new char[rec_len];
- memset(datacopy,EOS,rec_len);
- if ( datacopy!=0 )
- {
- memcpy(datacopy,data,rec_len);
- }
- }
- return datacopy;
- }
- // Insert or update record. could make seperate functions to force one
- // or the other. I prefer this.
- int put_rec(char *keystr,int tlen=0);
- // self explanatory...
- int del_rec(char *keystr);
- // allow user to get status after operation.
- int get_status(){ return status; }
- // gets a full FIL_SPEC record (see btrieve.h)
- void get_bstat(struct FIL_SPEC *);
- // returns rec_len private element.
- int get_len() { return rec_len; }
- // returns last_rec_len private element.
- int get_last_len() { return last_rec_len; }
- int get_pos(char *buf)
- {
- int tlen=4;
- char temp[256];
- status=BTRV(B_GET_POS,pos_blk,buf,&tlen,temp,key_num);
- return(status);
- }
- int set_pos(char *buf,char *keystr=0);
- int get_fname(char *tstr)
- {
- if ( tstr!=0 )
- {
- strcpy(tstr,fname);
- }
- return(tstr!=0);
- }
- int clone_file(char *destfname,int overwrite=1);
- };
- #endif